Interface: ZipFile


Auto.js Pro 9 Docs / zip / ZipFile

Interface: ZipFile

zip.ZipFile

open返回的对象,用于在压缩包中增删文件、获取文件头信息、解压等。

Table of contents

Methods

Methods

addFile

addFile(file, options?): Promise<void>

Add a file to the ZIP file.

Example

const zip = require('zip);
async function main() {
    const zipFile = await zip.open('test.zip');
    await zipFile.addFile('test.txt');
}
main();

Parameters

NameTypeDescription
filestringLocal file path
options?ZipOptionsCompress options

Returns

Promise<void>


addFiles

addFiles(fileList, options?): Promise<void>

Add multiple files to the ZIP file.

Parameters

NameTypeDescription
fileListstring[]Array of local file paths
options?ZipOptionsCompress options

Returns

Promise<void>


addFolder

addFolder(folder, options?): Promise<void>

Add a folder to the ZIP file.

Parameters

NameTypeDescription
folderstringFolder path
options?ZipOptionsCompress options

Returns

Promise<void>


extractAll

extractAll(dest, options?): Promise<void>

Extract all files from the ZIP file to the target path dest.

Parameters

NameTypeDescription
deststringExtract path
options?UnzipOptionsExtract options

Returns

Promise<void>


extractFile

extractFile(file, dest, options?, newFileName?): Promise<void>

Extract a file from the ZIP file. If the target path is invalid, this method will throw an exception.

Parameters

NameTypeDescription
filestringFile to extract
deststringDestination path
options?UnzipOptionsExtract options
newFileName?stringNew file name, optional

Returns

Promise<void>


getFileHeader

getFileHeader(file): any

Get the file header information of the specified file in the ZIP file. The file header information includes the checksum, whether the file is encrypted, comments, etc.

Parameters

NameTypeDescription
filestringFile path in the ZIP file

Returns

any

FileHeaderopen in new window


getFileHeaders

getFileHeaders(): any[]

Get the file header information of all files in the ZIP file. The file header information includes the checksum, whether the file is encrypted, comments, etc.

Returns

any[]

Array of FileHeaderopen in new window


getPath

getPath(): string

Get the path of the current ZIP file.

Returns

string


isEncrypted

isEncrypted(): boolean

Get whether the current ZIP file is an encrypted ZIP file.

Returns

boolean

Whether the current ZIP file is an encrypted ZIP file.


isValidZipFile

isValidZipFile(): boolean

Get whether the current ZIP file is a valid ZIP file. If the path is not a ZIP file or the file does not exist, return false.

Returns

boolean

Whether the current ZIP file is a valid ZIP file.


removeFile

removeFile(file): Promise<void>

Delete a file from the ZIP file. If the file does not exist, this method will throw an exception.

If the ZIP file is a segmented ZIP file, this method will throw an exception, because the zip specification does not allow updating a segmented ZIP file.

Parameters

NameTypeDescription
filestringFile to delete

Returns

Promise<void>


setPassword

setPassword(password): void

If the ZIP file is encrypted, you must use this function to set the correct password to decrypt the encrypted file. If you do not set the password, an exception will be thrown when you try to decrypt the encrypted ZIP file.

Parameters

NameTypeDescription
passwordstringPassword

Returns

void